path = r'C:\Users\Dapan1\Desktop\2024版康康笔记【下册】.pdf'


import fitz  # PyMuPDF

# 打开PDF文件
doc = fitz.open(path)
# 遍历书签
bookmarks_list = doc.get_toc(simple=False)
new_bookmarks_list = []
for bookmark in bookmarks_list:
    print(bookmark)
    new_bookmark = bookmark.copy()
    new_bookmark[-1]['zoom'] = 0.0

    # print(new_bookmark)
    new_bookmarks_list.append(new_bookmark)

# bookmarks =
# 将书签（大纲）添加到目标PDF
# print(new_bookmarks_list)
doc.set_toc(new_bookmarks_list)


# 保存修改后的PDF（如果需要）
doc.save("qq.pdf")

# 关闭文档
doc.close()
